package com.example.menuvirtualclient.presenter;

import java.util.List;

import com.example.menuvirtualclient.WsEnquiryClient;
import com.example.menuvirtualclient.core.Enquiry;
import com.example.menuvirtualclient.rule.*;
import com.example.menuvirtualclient.util.Common;
import com.example.menuvirtualclient.view.*;

public class EnquiryPresenter {

	private IEnquiryView _view;
	private EnquiryRule _rule;
	
	/**
	 * 
	 * @param view
	 */
	public EnquiryPresenter(IEnquiryView view){
		_view = view;
		_rule = new EnquiryRule(view.GetContext());
	}
	
	
	/**
	 * 
	 */
	public void LoadList(){
		try{
			List<Enquiry> list = _rule.GetList();
			_view.ShowEnquiry(list);
		}
		catch(Exception ex){
			HandleException(ex.getMessage());
		}
	}
	
	public void SaveEnquiryPerDay(String value){
		try{
			//Poner la logica
			WsEnquiryClient enquiryClient = new WsEnquiryClient(_view.GetContext(), this);
			enquiryClient.execute(Common.URL_WS + "saveEnquiry?value=" + value);			
			
			_view.CloseView();
		}
		catch(Exception ex){
			HandleException(ex.getMessage());
		}
	}
	
	/**
	 * 
	 * @param title
	 * @param message
	 */
	private void HandleException(String title, String message){
		_view.SetMessage(title, message);
	}
	/**
	 * 
	 * @param message
	 */
	private void HandleException(String message){
		HandleException("Error", message);
	}
	
}
